package org.lmind.example.common.web.internal;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.HashMap;

import org.junit.Test;
import org.lmind.example.common.core.HashMapAttributes;
import org.lmind.example.common.web.GeneralWebResourceResolver;

public class GeneralStaticResourceResolverTestCase {
	
	@Test
	public void test() {
		
		HashMapAttributes properties = new HashMapAttributes();
		//HashMap<String, String> properties = new HashMap<String, String>();
		properties.setValue("context.path", "http://static.example.com/webapp");
		
		GeneralWebResourceResolver resResolver = new GeneralWebResourceResolver();
		resResolver.setProperties(properties);
		resResolver.setPatterns(new ArrayList<ResourcePattern>());
		
		ResourcePattern pattern = new ResourcePattern();
		pattern.setPatternText("^image/(.*)$");
		pattern.setTemplate("${context.path}/${1}");
		resResolver.getPatterns().add(pattern);
		pattern = new ResourcePattern();
		pattern.setPatternText("^js/(.*)$");
		pattern.setTemplate("${context.path}/js/${1}");
		resResolver.getPatterns().add(pattern);

		assertEquals(resResolver.resolveUrl("image/test.png"), 
				"http://static.example.com/webapp/test.png");
		assertEquals(resResolver.resolveUrl("js/jquery.js"), 
				"http://static.example.com/webapp/js/jquery.js");
	}

}
